package com.jimmy.medical.repository;

import com.jimmy.medical.entity.RechargeRecord;
import com.jimmy.medical.entity.User;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RechargeRecordRepository extends JpaSpecificationExecutor<RechargeRecord>, PagingAndSortingRepository<RechargeRecord, Long> {

    RechargeRecord findFirstByPayFlowNo(String payFlowNo);

    @Query(value = "select count(*) from RechargeRecord where saleUser.id=?1 and createTime>=?2")
    int countByUser(Long userId, String startTime);

    @Query(value = "select sum(money) from RechargeRecord where saleUser.id=?1 and createTime>=?2")
    Double sumByUser(Long userId, String startTime);

    @Query(value = "from RechargeRecord where saleUser.id=?1 order by createTime desc")
    List<RechargeRecord> findAllBySaleUser(Long saleUserId);
}
